<?php

namespace app\model;

use think\Model;

class StatisticsVideoRechargeData extends Model
{
    // 设置当前模型对应的数据表
    protected $name = 'statistics_video_recharge_data';
    // 设置当前模型主键
    protected $pk = 'id';

    // 获取分页数据
    public function getPagingDataByWhere($where = [], $page = 1, $limit = 10, string $fields = 'id, name', $group = 'video_id, recharge_template_id', $order = 'recharge_price desc')
    {
        $total = $this::where($where)->group($group)->count();

        if ($total == 0) {
            return ['total' => 0, 'total_page' => 0, 'data' => []];
        }

        $offset = ($page - 1) * $limit;
        $totalPage = ceil($total / $limit);

        $data = $this::where($where)->field($fields)->group($group)->order($order)->limit($offset, $limit)->select()->toArray();

        return ['total' => $total, 'total_page' => $totalPage, 'data' => $data];
    }
}